/*
 * @Author: huangyq
 * @Date: 2022-04-06 14:39:50
 * @LastEditTime: 2022-04-21 15:23:38
 * @LastEditors: huangyq
 * @Description: token处理函数 检测到token 过期的处理
 * @FilePath: /vue3-boilerplate-pc-client/src/plugins/httpHelper/handler/TokenHandler.ts
 */

import { AxiosRequestConfig } from 'axios'
import { clearStorage, getStorage } from '@/utils'

export function createResponseTokenHandler() {
  return (code: string) => {
    if (code == '0109000') {
      setTimeout(() => {
        clearStorage()
        location.reload()
      }, 1500)
    }
  }
}

export function createRequestTokenHandler() {
  return (request: AxiosRequestConfig) => {
    request!.headers!.token = getStorage('token') || ''
  }
}
